import { createWebHistory, createRouter } from 'vue-router'
import Login from '../vitws/login.vue'
import Homea from '../vitws/home/homea.vue'
import Homeb from '../vitws/home/homeb.vue'
import Homec from '../vitws/home/homec.vue'
import Homed from '../vitws/home/homed.vue'
import Homee from '../vitws/home/homee.vue'
import Dd from '../vitws/dd.vue'

const routes = [
  { path: '/', redirect: '/homea' },
  { path: '/login', component: Login },
  { path: '/dd', component: Dd },
  {
    path: '/homea', component: Homea,
    children: [
      { path: 'homeb', component: Homeb },
      { path: 'homec', component: Homec },
      { path: 'homed', component: Homed },
      { path: 'homee', component: Homee },
    ]
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})
router.beforeEach((to, from) => {
  if (to.fullPath !== '/login') {
    let token = localStorage.getItem('token')
    if (!token) {
      return '/login'
    }
  }
})
export default router